<?php
class EditorWidget extends CWidget {
	public $type = 'ueditor';
	public $value = '';
	public $id = null;
	public $name = null;
	private $cs = null;
	public function init(){
		$this->cs = Yii::app()->clientScript;
		
		//以下为百度编辑器
		$init_act = '_init_' . $this->type;
		$this->$init_act();
	}
	
	public function run(){
		$run_act = '_' . $this->type;
		$this->$run_act();
	}
	
	private function _init_ueditor(){
		$this->cs->registerCssFile(BASE_URL . '/js/ueditor/themes/default/css/ueditor.css');
		$this->cs->registerScriptFile(BASE_URL . '/js/ueditor/ueditor.config.js', CClientScript::POS_END);
		$this->cs->registerScriptFile(BASE_URL . '/js/ueditor/ueditor.all.min.js', CClientScript::POS_END);
	}
	
	private function _ueditor(){
		echo '<div class="editor" style="width:auto;overflow-x:hidden">';
		echo CHtml::tag('script', array('type'=>'text/plain', 'id'=>$this->id), $this->value);
		echo '</div>';
		$this->cs->registerScript('editor_' . $this->id, '
var editor_' . $this->id . ' = UE.getEditor("' . $this->id . '",{
//focus时自动清空初始化时的内容
autoClearinitialContent:false,
textarea : "' . $this->name . '",
//关闭字数统计
wordCount:false,
//关闭elementPath
elementPathEnabled:false,
//默认的编辑区域高度
initialFrameHeight:300
});
	editor_' . $this->id . '.addListener("blur", function(){
		$("#' . $this->id . ' .edui-editor-toolbarbox").removeAttr("style").prev().remove();
	});
'
		);
	}
}

?>